const express = require('express');

const app = express();

app.use((request,response, next)=>{
    response.setHeader('Access-Control-Allow-Origin','*');
    response.setHeader('Access-Control-Allow-Headers','*');
    response.setHeader('Access-Control-Allow-Methods','*');
    next();
})
app.use(express.json());// 接收json格式的字符串
app.use(express.urlencoded({extended:false}));// 接收form表单数据
app.all('/server', (request,response)=>{
    response.json({
        code:0,
        msg:request.method + JSON.stringify(request.body)
    })
})

app.get('/timeout',(request,response)=>{
    setTimeout(()=>{
        response.json({
            code:0,
            msg:'取消'
        })
    },2000);
})

app.listen(8080,()=>{
    console.log('server run at 8080');
})